<?php
    include_once('connection.php');
?>
<H1 style="text-align:center">THÔNG BÁO</H1>
<hr />
<div id="top_content" style="width:725px; min-height:400px;">
<ul>
    <?php
		if(!isset($_GET['page'])) // current page
		{
			$p = 1;
		}
		else
		{
			$p = $_GET['page'];
		}
		$row = 10; //so record tren moi trang
		$div = 5; // so trang tren 1 phan doan
		$s = "SELECT * FROM tintuc";
		$rs = mysql_query($s, $connect);
		$total = mysql_num_rows($rs);
		$start = $p*$row - $row; //vi tri bat dau cua record trong trang
        $str = "SELECT * FROM tintuc ORDER BY ID DESC LIMIT $start,$row";
        $sql = mysql_query($str);
        while($rw = mysql_fetch_array($sql)) // hien thi du lieu
        {
            echo '<li style="padding-top:10px;"><a href=index.php?page=tintuc&id='.$rw['ID'].' style="text-decoration:none; font-size:20px;">'.$rw['TIEUDE'].'</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#CCC">'.$rw['THOIGIAN'].'</font></li>';
        }
    ?>
</ul>
</div>

<div id="bottom_content" style="width:725px; height:20px; text-align:center">
<?php
	$total_page = ceil($total/$row);
		$list_page = "";
		for($i=1; $i<=$total_page; $i++)
		{
			if($p == $i)
			{
				$list_page .= "<b>".$i." </b>";
			}
			else
			{
				$list_page .= "<a class='news' href='index.php?page=$i'> $i </a>";
			}
		}

		if($p > 1){
			$prev = $p - 1;
			$list_page .= "<a class='news' href='index.php?page=$prev'>Previous</a>";
		}

		if($p < $total_page){
			$prev = $p + 1;
			$list_page .= "<a class='news' href='index.php?page=$prev'>Next</a>";
		}
		echo $list_page;

?>
</div>